import { request } from '@/utils/request'
import type { WorkflowTemplate } from '@/types/workflow'

export class TemplateService {
    // 获取模板列表
    static async getTemplates(params?: Record<string, any>) {
        const response = await request.get('/templates', { params })
        return response.data
    }

    // 获取模板详情
    static async getTemplate(id: string) {
        const response = await request.get(`/templates/${id}`)
        return response.data
    }

    // 创建模板
    static async createTemplate(template: Partial<WorkflowTemplate>) {
        const response = await request.post('/templates', template)
        return response.data
    }

    // 更新模板
    static async updateTemplate(id: string, template: Partial<WorkflowTemplate>) {
        const response = await request.put(`/templates/${id}`, template)
        return response.data
    }

    // 删除模板
    static async deleteTemplate(id: string) {
        await request.delete(`/templates/${id}`)
    }

    // 克隆模板
    static async cloneTemplate(id: string) {
        const response = await request.post(`/templates/${id}/clone`)
        return response.data
    }

    // 导入模板
    static async importTemplate(file: File) {
        const formData = new FormData()
        formData.append('file', file)
        const response = await request.post('/templates/import', formData, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
        return response.data
    }
} 